home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / NewsWatcher 2.0d17 Source / source / font.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-20  |  2.6 KB  |  113 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     font.c
  4.  
  5.     This module handles the Font and Size menu commands.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include "glob.h"
  13. #include "font.h"
  14. #include "menus.h"
  15. #include "open.h"
  16. #include "resize.h"
  17. #include "util.h"
  18. #include "wind.h"
  19.  
  20.  
  21. /*    UpdateFontInfo updates the font information for a window */
  22.  
  23. static void UpdateFontInfo (WindowPtr wind)
  24. {
  25.     FontInfo fontInfo;
  26.     TWindow **info;
  27.     ListHandle theList;
  28.     TEHandle theTE;
  29.     Point newSize;
  30.         
  31.     GetFontInfo(&fontInfo);
  32.     info = (TWindow**)GetWRefCon(wind);
  33.     
  34.     switch ((**info).kind) {
  35.         case kFullGroup:
  36.         case kNewGroup:
  37.         case kUserGroup:
  38.         case kSubject:
  39.             theList = (**info).theList;
  40.             newSize.h = (**theList).cellSize.h;
  41.             newSize.v = fontInfo.ascent+fontInfo.descent+fontInfo.leading;
  42.             LCellSize(newSize,theList);
  43.             CalcWindowHCoords(wind);
  44.             break;
  45.         case kArticle:
  46.         case kMiscArticle:
  47.         case kMailMessage:
  48.         case kPostMessage:
  49.             theTE = (**info).theTE;
  50.             (**theTE).txFont = wind->txFont;
  51.             (**theTE).txFace = wind->txFace;
  52.             (**theTE).txMode = wind->txMode;
  53.             (**theTE).txSize = wind->txSize;
  54.             (**theTE).lineHeight = 
  55.                 fontInfo.ascent+fontInfo.descent+fontInfo.leading;
  56.             (**theTE).fontAscent = fontInfo.ascent;
  57.             CalcPanelHeight(wind);
  58.             break;
  59.     }
  60.     SizeContents(wind);
  61.     if (gPrefs.zoomWindows) {
  62.         DoZoom(wind, inZoomOut);
  63.     } else {
  64.         SetWindowNeedsZooming(wind);
  65.     }
  66. }
  67.  
  68. void FontWasChanged (Boolean listFont)
  69. {
  70.     WindowPtr    wind;
  71.     WindowPeek    peek;
  72.     TWindow **    info;
  73.     EWindowKind kind;
  74.     short        fontID, fontSize;
  75.     Boolean        changeWind;
  76.     GrafPtr        savePort;
  77.  
  78.     /* Figure out the new font ID and size */
  79.     if (listFont) {
  80.         GetFNum(gPrefs.listFont, &fontID);
  81.         fontSize = gPrefs.listSize;
  82.     } else {
  83.         GetFNum(gPrefs.textFont, &fontID);
  84.         fontSize = gPrefs.textSize;
  85.     }
  86.  
  87.     /* Loop through all the windows and see if they need updating */ 
  88.     GetPort(&savePort);
  89.     wind = FrontWindow();
  90.     while (wind != nil) {
  91.         peek = (WindowPeek)wind;
  92.         if (!IsStatusWindow(wind) && IsAppWindow(wind)) {
  93.             info = (TWindow**)GetWRefCon(wind);
  94.             kind = (**info).kind;
  95.             changeWind = false;
  96.             if (listFont) {
  97.                 changeWind = (kind <= kSubject);
  98.             } else {
  99.                 changeWind = (kind >= kArticle && kind <= kPostMessage);
  100.             }
  101.             if (changeWind) {
  102.                 if (!listFont) (**(**info).theTE).txFont = fontID;
  103.                 SetPort(wind);
  104.                 TextFont(fontID);
  105.                 TextSize(fontSize);
  106.                 UpdateFontInfo(wind);
  107.                 InvalRect(&wind->portRect);
  108.             }
  109.         }
  110.         wind = (WindowPtr)peek->nextWindow;
  111.     }
  112. }
  113.